package com.ruoyi.project.jiaqin.downquotation.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.jiaqin.downquotation.domain.DownQuotation;
import com.ruoyi.project.jiaqin.downquotation.service.IDownQuotationService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 羽绒行情Controller
 *
 * @author admin
 * @date 2021-01-29
 */
@Controller
@RequestMapping("/jiaqin/downquotation")
public class DownQuotationController extends BaseController
{
    private String prefix = "jiaqin/downquotation";

    @Autowired
    private IDownQuotationService downQuotationService;

    @RequiresPermissions("jiaqin:downquotation:view")
    @GetMapping()
    public String downquotation()
    {
        return prefix + "/downquotation";
    }

    /**
     * 查询羽绒行情列表
     */
    @RequiresPermissions("jiaqin:downquotation:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DownQuotation downQuotation)
    {
        startPage();
        downQuotation.setDelFlag(0);
        List<DownQuotation> list = downQuotationService.selectDownQuotationList(downQuotation);
        return getDataTable(list);
    }

    /**
     * 导出羽绒行情列表
     */
    @RequiresPermissions("jiaqin:downquotation:export")
    @Log(title = "羽绒行情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DownQuotation downQuotation)
    {
        List<DownQuotation> list = downQuotationService.selectDownQuotationList(downQuotation);
        ExcelUtil<DownQuotation> util = new ExcelUtil<DownQuotation>(DownQuotation.class);
        return util.exportExcel(list, "downquotation");
    }

    /**
     * 新增羽绒行情
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存羽绒行情
     */
    @RequiresPermissions("jiaqin:downquotation:add")
    @Log(title = "羽绒行情", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DownQuotation downQuotation)
    {
        return toAjax(downQuotationService.insertDownQuotation(downQuotation));
    }

    /**
     * 修改羽绒行情
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        DownQuotation downQuotation = downQuotationService.selectDownQuotationById(id);
        mmap.put("downQuotation", downQuotation);
        return prefix + "/edit";
    }

    /**
     * 修改保存羽绒行情
     */
    @RequiresPermissions("jiaqin:downquotation:edit")
    @Log(title = "羽绒行情", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DownQuotation downQuotation)
    {
        return toAjax(downQuotationService.updateDownQuotation(downQuotation));
    }

    /**
     * 删除羽绒行情
     */
    @RequiresPermissions("jiaqin:downquotation:remove")
    @Log(title = "羽绒行情", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(downQuotationService.deleteDownQuotationByIds(ids));
    }
}
